<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //map方法模拟
        Array.prototype.Mmap=function(fn){
            let oldArr=this
            let newArr=[]
            for(i=0;i<oldArr.length;i++){
                newArr.push(fn(oldArr[i]))
            }
            return newArr
        }

        let arr=[1,2,3,4,5,6,7]

        let newArrTwo=arr.Mmap(item=>{
            return item+100
        })
        console.log(newArrTwo)
        //filter方法模拟
        Array.prototype.Mfilter=function(fn){
            let oldArr=this
            let newArr=[]
            for(let i=0;i<oldArr.length;i++){
                if(fn(oldArr[i])){
                    newArr.push(oldArr[i])
                }
            }
            return newArr
        }

        let newArrThree=arr.Mfilter(item=>{
            return item>3
        })
        console.log(newArrThree)

        //push方法模拟
        Array.prototype.Mpush=function(n){
            let oldArr=this
            oldArr[oldArr.length]=n
            return oldArr
        }
        console.log(arr)
        console.log(arr.Mpush(8))
        console.log(arr.Mpush(8))
        console.log(arr.Mpush(8))


        //pop方法模拟
        Array.prototype.Mpop=function(){
            let oldArr=this
            oldArr.length=oldArr.length-1
            return oldArr
        }
        console.log(arr.Mpop())
        console.log(arr.Mpop())
        console.log(arr.Mpop())
        console.log(arr.Mpop())
        console.log(arr.Mpop())
        //构造函数
        function People(name,age){
            this.name=name
            this.age=age
        }
        let f=new People('f',18 )

    </script>
</body>
</html>